package com.example.thigiuaki;

import java.util.ArrayList;

import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class DBnhanvien {
	private SQLiteDatabase database=null;
	private Activity context;
	
	public DBnhanvien() {
		
	}
	public DBnhanvien(Activity context) {
		//this.database=database;
		this.context=context;
		DBConfig config=new DBConfig(context,"nhanvien.db");
		database=config.getdatabase();
	}
	public void doDeletenhanvien(nhanvien nv)
	{
		//database.delete("nhanvien", null, null);
		String id=nv.getId();
		database.delete("nhanvien", 
				"id=?", 
				new String[]{id});
	}
	public ArrayList<nhanvien> findALL(){
		
		ArrayList<nhanvien> list=new ArrayList<nhanvien>();
		Cursor c=database.query("nhanvien",
				null, null, null, null, null, null);
		c.moveToFirst();
	
		while(c.isAfterLast()==false)
		{
			nhanvien nv=new nhanvien();
			nv.setId(c.getString(0));
			nv.setName(c.getString(1));
			if(c.getString(2).equals("F"))
				nv.setGenter(true);
			else nv.setGenter(false);
			nv.setAddrcity(c.getString(3));
			list.add(nv);
			c.moveToNext();
		}
		
		c.close();
		return list;
	}
	public boolean createnhanvien(nhanvien nv){
		
		ContentValues values=new ContentValues();
		values.put("id", nv.getId());
		values.put("name", nv.getName());
		values.put("gender", nv.isGenter());
		values.put("addrcity", nv.getAddrcity());
		
		if(database.insert("nhanvien", null, values)==-1){
			return false;
		}
		else{
			return true;
		}

	}

}
